package com.chcit.custom;

import android.content.Intent;
import android.support.design.widget.TextInputEditText;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.chcit.custom.view.edit.ImageInputEditText;
import com.chcit.custom.view.loader.LoaderStyle;
import com.chcit.custom.view.loader.LoadingDialog;
import com.chcit.custom.view.loader.QuickLoader;
import com.yzq.zxinglibrary.android.CaptureActivity;
import com.yzq.zxinglibrary.bean.ZxingConfig;
import com.yzq.zxinglibrary.common.Constant;

public class MainActivity extends AppCompatActivity {
    private static final int REQUEST_CODE_SCAN = 12;
    private int i;
    private ImageInputEditText imgEdit;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button style1 = findViewById(R.id.style1);
        Button style2 = findViewById(R.id.style2);
        imgEdit = findViewById(R.id.image_edit);
        Intent intent = new Intent(MainActivity.this, CaptureActivity.class);
        /*ZxingConfig是配置类
         *可以设置是否显示底部布局，闪光灯，相册，
         * 是否播放提示音  震动
         * 设置扫描框颜色等
         * 也可以不传这个参数
         * */
        ZxingConfig config = new ZxingConfig();
        config.setPlayBeep(true);//是否播放扫描声音 默认为true
        config.setShake(true);//是否震动  默认为true
        config.setDecodeBarCode(true);//是否扫描条形码 默认为true
        config.setReactColor(R.color.colorAccent);//设置扫描框四个角的颜色 默认为白色
        config.setFrameLineColor(R.color.colorAccent);//设置扫描框边框颜色 默认无色
        config.setScanLineColor(R.color.colorAccent);//设置扫描线的颜色 默认白色
        config.setFullScreenScan(false);//是否全屏扫描  默认为true  设为false则只会在扫描框中扫描
        intent.putExtra(Constant.INTENT_ZXING_CONFIG, config);
        imgEdit.setImageClick(l->{
            Toast.makeText(this,"点击了image",Toast.LENGTH_LONG).show();
            startActivityForResult(intent, REQUEST_CODE_SCAN);
        });
        style1.setOnClickListener(l->{
            startActivity(new Intent(this,DropDownActivity.class));

        });
        MyTextView textView = new MyTextView(this);
        addContentView(textView,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        style2.setOnClickListener(l->{

            if(i%2 == 0){
                QuickLoader.showLoading(this,LoaderStyle.BallPulseIndicator.name(),true);

            }else{
                QuickLoader.stopLoading();
            }
            i++;

        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // 扫描二维码/条码回传
        if (requestCode == REQUEST_CODE_SCAN && resultCode == RESULT_OK) {
            if (data != null) {

                String content = data.getStringExtra(Constant.CODED_CONTENT);
                imgEdit.setText("扫描结果为：" + content);
            }
        }
    }
}
